This page last changed on Oct 11, 2006 by andrew.

Firstly, what is the difference between these two receivers? Well, the TransacteJmsMessageReceiver is able to receive a JmsMessage in an XA Transaction whilst the TransactedSingleResourceJmsMessageReceiver can receive messages in Single Resource Transactions but not XA. So one might ask, why not always use an XA message receiver since it can also handle single resource transactions. Well yes, you would be right, you could, but this would incur some performance penalties if you were just using Single Resource transactions. This is because, for XA transactions one would need to poll for messages, whilst for Single Resource transactions one can make use of a MessageListener.

So , instead of these steps:

  1. Create a transaction.
  2. Poll for a message.
  3. If no message is present, close the transaction, otherwise process in a transaction context.
  4. Loop to step 1.

one can make use of a message Listener which will:

  1. Listen for an incoming message.
  2. When the message is received, create a transaction.
  3. Process in a transaction context.
  4. Loop to step 1.

It should be clear enough that the latter flow is more efficient, especially if the traffic isn't very high.

In order to do this we will need to override the default message receiver. Programmatically this is done using the following when creating the new jms connector :

JmsConnector connector = new JmsConnector();
Map overrides = new HashMap();
overrides.put("message.receiver", TransactedSingleResourceJmsMessageReceiver.class.getName());
overrides.put("transacted.message.receiver", TransactedSingleResourceJmsMessageReceiver.class.getName());
connector.setServiceOverrides(overrides);

Whilst in XML Configuration this would be done by adding the following to the connector configuration:

<connector name="myJmsConnector" className="org.mule.providers.jms.JmsConnector">
    <properties>
        ...
        <map name="serviceOverrides">
            <property name="message.receiver" value="org.mule.providers.jms.TransactedSingleResourceJmsMessageReceiver"/>
            <property name="transacted.message.receiver" value="org.mule.providers.jms.TransactedSingleResourceJmsMessageReceiver"/>
        </map>
    </properties>
</connector>

The rest of configuration is identical as if you were using the default Message Receiver, you are simply plugging a different Message Receiver.

Document generated by Confluence on Nov 27, 2006 10:27